package cn.com.lms.business.examRewrite.service;

import cn.com.lms.business.core.constant.ErrorEnum;
import cn.com.lms.business.core.util.SystemUserUtil;
import cn.com.lms.business.exam.enums.PaperTypeEnum;
import cn.com.lms.business.examRewrite.persistence.entity.PaperQuestionReWrite;
import cn.com.lms.business.examRewrite.persistence.entity.PaperReWrite;
import cn.com.lms.business.examRewrite.persistence.entity.PaperSubjectReWrite;
import cn.com.lms.business.examRewrite.persistence.repository.PaperReWriteDao;
import cn.com.lms.business.examRewrite.vo.PaperListReWriteVO;
import cn.com.lms.business.user.persistence.entity.SysUserVo;
import com.bnzj.core.exception.BusinessException;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class PaperReWriteService extends BaseService<PaperReWriteDao, PaperReWrite,Long> {
    @Autowired
    PaperSubjectReWriteService paperSubjectReWriteService;

    @Autowired
    PaperExtraReWriteService paperExtraReWriteService;

    @Autowired
    PaperQuestionReWriteService paperQuestionReWriteService;

    /**
     * 获取首页的数据
     * @return
     */
    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "select p.id,p.paper_name,p.type,(case p.type when 1 then '固定' else '随机' end) type_name,p.is_delete,p.is_enable,p.create_time,p.creator_name,e.paper_score,e.subject_count" ;
        String whereSQL = " from bnz_exam_paper p left join bnz_exam_paper_extra e on p.id = e.paper_id where 1=1 ";
        QueryHelpBean queryHelpBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, PaperListReWriteVO.class);
        return queryHelpBean;
    }

    /**
     * 删除、批量删除
     * @param result
     * @param ids
     * @return
     */
    public Integer deleteReWrite(boolean result, List<Long> ids) {

        // 删除 bnz-exam-extra
        paperExtraReWriteService.deletePaperExtraReWriteByPaperId(ids);
        // 删除 bnz-exam-question
        paperQuestionReWriteService.deletePaperQuestionReWriteByPaperId(result,ids);
        // 删除 bnz-exam-question-subject
        paperSubjectReWriteService.deletePaperSubjectReWriteByPaperId(result,ids);
        // 删除 bnz-exam-paper
        return repository.deleteReWrite(result,ids);
    }

    /**
     * 启用
     * @param result
     * @param ids
     * @return
     */
    public Integer enableReWrite(boolean result, List<Long> ids) {
        return repository.enableReWrite(result,ids);
    }

    /**
     * 禁用
     * @param result
     * @param ids
     * @return
     */
    public Integer disableReWrite(boolean result, List<Long> ids) {
        return repository.disableReWrite(result,ids);
    }

    /**
     * 保存数据
     * @param paperReWrite
     */
    @Transactional(rollbackFor = Exception.class)
    public PaperReWrite saveDate(PaperReWrite paperReWrite) {
        // 保存 bnz_exam_paper
        PaperReWrite result = save(paperReWrite);
        // 试卷总分数
        Integer paperTotalScore = 0;
        // 试卷总科目数
        Integer PaperTotalCount = 0;
        // 试卷分数集合
        List<Integer> PaperScoreList = new ArrayList<>();
        // 试卷题目集合
        List<Integer> PaperCountList = new ArrayList<>();
        // 判断试卷类型是固定还是随机
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(paperReWrite.getType())){
            // 固定出题
            List<PaperSubjectReWrite> paperSubjectList = paperReWrite.getPaperSubjectList();
            // 试卷题目数
            PaperCountList.add(paperSubjectList.size());
            if (paperSubjectList!=null && paperSubjectList.size()>0){
                List<PaperSubjectReWrite> paperSubjectReWrites = paperSubjectList.stream().map(item -> {
                    PaperSubjectReWrite paperSubjectReWrite = new PaperSubjectReWrite();
                    // 添加数据
                    paperSubjectReWrite.setPaperId(result.getId());
                    paperSubjectReWrite.setCreator(result.getCreator());
                    paperSubjectReWrite.setCreatorName(result.getCreatorName());
                    paperSubjectReWrite.setCreateTime(result.getCreateTime());
                    paperSubjectReWrite.setSubjectId(item.getSubjectId());
                    paperSubjectReWrite.setScore(item.getScore());
                    paperSubjectReWrite.setIsDelete(item.getIsDelete() == null ? false : item.getIsDelete());
                    paperSubjectReWrite.setSortId(item.getSortId() == null ? paperSubjectList.indexOf(item) + 1 : item.getSortId());
                    PaperScoreList.add(paperSubjectReWrite.getScore());
                    return paperSubjectReWrite;
                }).collect(Collectors.toList());
                // 保存bnz_exam_paper_subject数据 paperSubjectReWrites
                paperSubjectReWriteService.saveAll(paperSubjectReWrites);
            }

        }
        else if (PaperTypeEnum.RANDOM_QUESTION.getValue().equals(paperReWrite.getType())){
            // TODO 随机出题
            // 获取到PaperQuestionList的数据
            List<PaperQuestionReWrite> paperQuestionList = paperReWrite.getPaperQuestionList();
            if (paperQuestionList!=null && paperQuestionList.size()>0){
                List<PaperQuestionReWrite> paperQuestionReWrites = paperQuestionList.stream().map(item -> {
                    // 创建一个 PaperQuestionReWrite 对象
                    PaperQuestionReWrite paperQuestionReWrite = new PaperQuestionReWrite();
                    paperQuestionReWrite.setPaperId(result.getId());
                    paperQuestionReWrite.setCreator(result.getCreator());
                    paperQuestionReWrite.setCreateTime(result.getCreateTime());
                    paperQuestionReWrite.setCreatorName(result.getCreatorName());
                    paperQuestionReWrite.setQuestionId(item.getQuestionId());
                    paperQuestionReWrite.setSingleCount(getValue(item.getSingleCount()));
                    paperQuestionReWrite.setMultipleCount(getValue(item.getMultipleCount()));
                    paperQuestionReWrite.setJudgeCount(getValue(item.getJudgeCount()));
                    paperQuestionReWrite.setFillCount(getValue(item.getFillCount()));
                    paperQuestionReWrite.setExplainCount(getValue(item.getExplainCount()));
                    paperQuestionReWrite.setIsDelete(item.getIsDelete()==null?false:item.getIsDelete());
                    // 保存分数总数
                    PaperScoreList.add(PaperCountScore(result,item));
                    // 保存题目总数
                    PaperCountList.add(PaperCountSubject(item));
                    return paperQuestionReWrite;
                }).collect(Collectors.toList());
                paperQuestionReWriteService.saveAll(paperQuestionReWrites);
            }

        }
        else {
            // 异常
            throw new BusinessException(ErrorEnum.PARAMETER_CANNOT_BE_EMPTY.getMessage(), "" + ErrorEnum.PARAMETER_CANNOT_BE_EMPTY.getCode());
        }
        if (PaperScoreList!=null && PaperScoreList.size()>0){
            // 计算分数总数
             paperTotalScore = PaperScoreList.stream().collect(Collectors.summingInt(Integer::intValue));
        }
        if (PaperCountList!=null && PaperCountList.size()>0){
            // 计算题目个数
            PaperTotalCount = PaperCountList.stream().collect(Collectors.summingInt(Integer::intValue));
        }
        paperExtraReWriteService.savePaperExtra(result.getId(),paperTotalScore,PaperTotalCount);
        return result;
    }

    /**
     * 计算题目总数
     * @param paperQuestionList
     * @return
     */
    private Integer PaperCountSubject(PaperQuestionReWrite paperQuestionList) {
        Integer totalCount = 0;
        // 多选题数量
        totalCount += getValue(paperQuestionList.getMultipleCount());
        // 填空题数量
        totalCount += getValue(paperQuestionList.getFillCount());
        // 问答题数量
        totalCount += getValue(paperQuestionList.getExplainCount());
        // 单选题数量
        totalCount += getValue(paperQuestionList.getSingleCount());
        // 判断题数量
        totalCount += getValue(paperQuestionList.getJudgeCount());
        return totalCount;
    }

    /**
     * 计算分数总数
     * @param paperReWrite
     * @param paperQuestionList
     * @return
     */
    private Integer PaperCountScore(PaperReWrite paperReWrite,PaperQuestionReWrite paperQuestionList) {
        Integer totalScore = 0;
        // 问答题分数
        totalScore += getValue(paperReWrite.getExplainScore())* getValue(paperQuestionList.getExplainCount());
        // 填空题分数
        totalScore += getValue(paperReWrite.getFillScore()) * getValue(paperQuestionList.getFillCount());
        // 判断题分数
        totalScore += getValue(paperReWrite.getJudgeScore()) * getValue(paperQuestionList.getJudgeCount());
        // 多选题分数
        totalScore += getValue(paperReWrite.getMultipleScore()) * getValue(paperQuestionList.getMultipleCount());
        // 单选题分数
        totalScore += getValue(paperReWrite.getSingleScore()) * getValue(paperQuestionList.getSingleCount());
        return totalScore;
    }

    /**
     * 如果实体类的值为空，就返回0,
     * @param value
     * @return
     */
    private Integer getValue(Integer value){
        if (value==null){
            return 0;
        }
            return value;
    }

    /**
     * 通过id获取数据
     * @param id paperReWrite的id
     * @return PaperReWrite 试卷的实体类
     */
    public PaperReWrite findId(Long id,Boolean result) {
        // 获取PaperReWrite数据
        PaperReWrite paperReWrite = repository.getPaperReWriteById(id,result);
        if (paperReWrite ==null){
            throw new BusinessException(ErrorEnum.RECORD_NOT_EXIST.getMessage(), "" + ErrorEnum.RECORD_NOT_EXIST.getCode());
        }
        if (PaperTypeEnum.FIXED_SELECTION.getValue()==paperReWrite.getType()){
            // 判断试卷是固定
            List<PaperSubjectReWrite> paperSubjectList = paperSubjectReWriteService.findByIdAndIsDelete(id,false);
            paperReWrite.setPaperSubjectList(paperSubjectList);
        }
        if (PaperTypeEnum.RANDOM_QUESTION.getValue()==paperReWrite.getType()){
            // 判断试卷是随机
            List<PaperQuestionReWrite> paperQuestionList = paperQuestionReWriteService.findByIdAndIsDelete(id,false);
            paperReWrite.setPaperQuestionList(paperQuestionList);
        }
        return paperReWrite;
    }

    /**
     * 修改数据
     * @param paper_target
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateSave(PaperReWrite  paperReWrite, PaperReWrite paper_target) {
        BeanUtils.copyProperties(paperReWrite,paper_target);
        // 保存PaperReWrite数据
        save(paper_target);
        // 总分数
        int paperScore = 0;
        // 题目数量
        int subjectCount = 0;
        // 固定试卷
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(paperReWrite.getType())){
            // 固定试卷
            List<PaperSubjectReWrite> paperSubjectList = paperReWrite.getPaperSubjectList();
            if (paperSubjectList!=null && paperSubjectList.size()>0){
                subjectCount = paperSubjectList.size();
                paperScore = paperSubjectList.stream().mapToInt(PaperSubjectReWrite::getScore).sum();
            }
            List<PaperSubjectReWrite> databasePaper = paperSubjectReWriteService.findByIdAndIsDelete(paperReWrite.getId(), false);
            if (databasePaper!=null && databasePaper.size()>0){
                // 判断数据是否存在
                ObjectDataExist(paperSubjectList,databasePaper,paper_target.getId(),paperReWrite.getType());
            }
        }
        // 随机试卷
        else if (PaperTypeEnum.RANDOM_QUESTION.getValue().equals(paperReWrite.getType())){
            List<PaperQuestionReWrite> paperQuestionList = paperReWrite.getPaperQuestionList();
            if (paperQuestionList!=null && paperQuestionList.size()>0){
                // 分数list
                List<Integer> ScoreList = new ArrayList<>();
                // 题目list
                List<Integer> CountList = new ArrayList<>();
                paperQuestionList.forEach(item->{
                    Integer Score = PaperCountSubject(item);
                    Integer Count = PaperCountScore(paper_target, item);
                    ScoreList.add(Score);
                    CountList.add(Count);
                });
                if (!CollectionUtils.isEmpty(ScoreList)){
                     paperScore = ScoreList.stream().collect(Collectors.summingInt(Integer::intValue));
                }
                if (!CollectionUtils.isEmpty(CountList)){
                    subjectCount = CountList.stream().collect(Collectors.summingInt(Integer::intValue));
                }
                // TODO 随机试卷
                List<PaperQuestionReWrite> databasePaper = paperQuestionReWriteService.findByIdAndIsDelete(paperReWrite.getId(), false);
                if (databasePaper!=null && databasePaper.size()>0){
                    // 判断数据是否存在
                    ObjectDataExist(paperQuestionList,databasePaper,paper_target.getId(),paperReWrite.getType());
                }
            }
        }
        // 保存分数
        paperExtraReWriteService.savePaperExtra(paper_target.getId(),paperScore,subjectCount);

    }

    /**
     * 设置为泛型 保存数据
     * @param paperSubjectList
     * @param id
     * @param type
     * @param <T>
     */
    private<T> void dataSave(List<T> paperSubjectList,Long id,short type) {
        // 判断试卷类型
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(type)){
            // 固定
            List<PaperSubjectReWrite> paperSubjectList1 = (List<PaperSubjectReWrite>) paperSubjectList;
            List<PaperSubjectReWrite> subjectReWrites = paperSubjectList1.stream().map(item -> {
                SysUserVo user = SystemUserUtil.getCurrentUser();
                item.setIsDelete(false);
                item.setPaperId(id);
                item.setCreateTime(new Date());
                // TODO 需要优化的
                item.setSortId(paperSubjectList1.indexOf(item)+1);
                item.setCreator(String.valueOf(user.getId()));
                item.setCreatorName(user.getCname());
                return item;
            }).collect(Collectors.toList());
            paperSubjectReWriteService.saveAll(subjectReWrites);
        }else {
            // 随机
            List<PaperQuestionReWrite> paperSubjectList1 = (List<PaperQuestionReWrite>) paperSubjectList;
            List<PaperQuestionReWrite> subjectReWrites = paperSubjectList1.stream().map(item -> {
                SysUserVo user = SystemUserUtil.getCurrentUser();
                item.setIsDelete(false);
                item.setPaperId(id);
                item.setCreateTime(new Date());
                item.setCreator(String.valueOf(user.getId()));
                item.setCreatorName(user.getCname());
                return item;
            }).collect(Collectors.toList());
            paperQuestionReWriteService.saveAll(subjectReWrites);
        }

    }

    /**
     * 设置为泛型 数据不同的三种情况
     * @param paperSubjectList
     * @param databasePaper
     * @param paperId
     * @param type
     * @param <T>
     */
    private<T> void ObjectDataExist(List<T> paperSubjectList, List<T> databasePaper, Long paperId,Short type) {
        // 判断试卷类型
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(type)){
            // 固定
            if (paperSubjectList != null && paperSubjectList.size() > 0 && databasePaper != null && databasePaper.size() > 0) {
                // 相等
                if (paperSubjectList.size() == databasePaper.size()) {
                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0){
                        List<PaperSubjectReWrite> base = (List<PaperSubjectReWrite>) listHashMap.get("databases");
                        List<PaperSubjectReWrite> paper = (List<PaperSubjectReWrite>) listHashMap.get("paper");
                        if (base != null && base.size() > 0) {
                            dataPaperSave(paper,base,type);
                        }
                    }
                }
                // 小于
                else if (paperSubjectList.size() > databasePaper.size()){
                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0){
                        List<PaperSubjectReWrite> base = (List<PaperSubjectReWrite>) listHashMap.get("databases");
                        List<PaperSubjectReWrite> paper = (List<PaperSubjectReWrite>) listHashMap.get("paper");
                        if (base.size()==0 && paper!=null && paper.size()>0){
                            //保存数据库没有存在的数据
                            dataSave(paper,paperId,type);
                        }else {
                            if (base != null && base.size() > 0) {
                                dataPaperSave(paper,base,type);
                            }
                        }
                    }
                }
                // 大于
                else {

                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0) {
                        List<PaperSubjectReWrite> base = (List<PaperSubjectReWrite>) listHashMap.get("databases");
                        List<PaperSubjectReWrite> paper = (List<PaperSubjectReWrite>) listHashMap.get("paper");
                        if (base !=null && base.size()>0 && paper.size()==0){
                            // 删除数据
                            for (PaperSubjectReWrite paperSubjectReWrite : base) {
                                paperSubjectReWriteService.deleteById(paperSubjectReWrite.getId());
                            }
                        }else {
                            if (base.size() > 0 && paper.size() > 0) {
                                dataPaperSave(paper,base,type);
                            }
                        }
                    }
                }
            }
        }else {
            // 随机
            if (paperSubjectList != null && paperSubjectList.size() > 0 && databasePaper != null && databasePaper.size() > 0) {
                // 相等
                if (paperSubjectList.size() == databasePaper.size()) {
                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0){
                        List<PaperQuestionReWrite> base = (List<PaperQuestionReWrite>) listHashMap.get("databases");
                        List<PaperQuestionReWrite> paper = (List<PaperQuestionReWrite>) listHashMap.get("paper");
                        if (base != null && base.size() > 0) {
                            dataPaperSave(paper,base,type);
                        }
                    }
                }
                // 小于
                else if (paperSubjectList.size() > databasePaper.size()){
                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0){
                        List<PaperQuestionReWrite> base = (List<PaperQuestionReWrite>) listHashMap.get("databases");
                        List<PaperQuestionReWrite> paper = (List<PaperQuestionReWrite>) listHashMap.get("paper");
                        if (base.size()==0 && paper!=null && paper.size()>0){
                            //保存数据库没有存在的数据
                            dataSave(paper,paperId,type);
                        }else {
                            if (base != null && base.size() > 0) {
                                dataPaperSave(paper,base,type);
                            }
                        }
                    }
                }
                // 大于
                else {

                    // 判断数据数据有相等
                    HashMap<String, List<T>> listHashMap = sameObjectCount(paperSubjectList, databasePaper,type);
                    if (listHashMap.size()>0) {
                        List<PaperQuestionReWrite> base = (List<PaperQuestionReWrite>) listHashMap.get("databases");
                        List<PaperQuestionReWrite> paper = (List<PaperQuestionReWrite>) listHashMap.get("paper");
                        if (base !=null && base.size()>0 && paper.size()==0){
                            // 删除数据
                            for (PaperQuestionReWrite paperSubjectReWrite : base) {
                                paperSubjectReWriteService.deleteById(paperSubjectReWrite.getId());
                            }
                        }else {
                            if (base.size() > 0 && paper.size() > 0) {
                                dataPaperSave(paper,base,type);
                            }
                        }
                    }
                }
            }
        }

    }

    /**
     * 设置为泛型 判断两个集合是否相同
     * @param paper
     * @param databases
     * @param type
     * @param <T>
     * @return
     */
    private<T> HashMap<String, List<T>> sameObjectCount(List<T> paper, List<T> databases, Short type){
        HashMap<String, List<T>> listHashMap = new HashMap<>();
        // 判断试卷类型
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(type)){
            // 固定
            List<PaperSubjectReWrite> paperList = new ArrayList<>();
            List<PaperSubjectReWrite> paper1 = (List<PaperSubjectReWrite>) paper;
            List<PaperSubjectReWrite> databases1 = (List<PaperSubjectReWrite>) databases;
            for (PaperSubjectReWrite paperSubjectReWrite : paper1) {
                for (PaperSubjectReWrite database : databases1) {
                    if (paperSubjectReWrite.getScore().equals(database.getScore()) && paperSubjectReWrite.getSubjectId().equals(database.getSubjectId())){
                        databases.remove(database);
                        paperList.add(paperSubjectReWrite);
                        break;
                    }
                }
            }
            paperList.stream().forEach(item->paper.remove(item));
        }else {
            //随机
            List<PaperQuestionReWrite> paperList = new ArrayList<>();
            List<PaperQuestionReWrite> paper1 = (List<PaperQuestionReWrite>) paper;
            List<PaperQuestionReWrite> databases1 = (List<PaperQuestionReWrite>) databases;
            for (PaperQuestionReWrite paperSubjectReWrite : paper1) {
                for (PaperQuestionReWrite database : databases1) {
                    if (paperSubjectReWrite.getQuestionId().equals(database.getQuestionId())
                            && getValue(paperSubjectReWrite.getSingleCount()).equals(getValue(database.getSingleCount()))
                            && getValue(paperSubjectReWrite.getMultipleCount()).equals(getValue(database.getMultipleCount()))
                            && getValue(paperSubjectReWrite.getJudgeCount()).equals(getValue(database.getJudgeCount()))){
                        databases.remove(database);
                        paperList.add(paperSubjectReWrite);
                        break;
                    }
                }
            }
            paperList.stream().forEach(item->paper.remove(item));
        }
        listHashMap.put("databases",databases);
        listHashMap.put("paper",paper);
        return listHashMap;
    }

    /**
     * 设置为泛型 判断数据是否存在，不存在添加数据
     * @param paper
     * @param base
     * @param type
     * @param <T>
     */
    private<T> void dataPaperSave(List<T> paper, List<T> base,Short type){
        // 判断试卷类型
        if (PaperTypeEnum.FIXED_SELECTION.getValue().equals(type)){
            // 固定
            List<PaperSubjectReWrite> paper1 = (List<PaperSubjectReWrite>) paper;
            List<PaperSubjectReWrite> base1 = (List<PaperSubjectReWrite>) base;
            base1.stream().map(item -> {
                for (PaperSubjectReWrite paperSubjectReWrite : paper1) {
                    if (paperSubjectReWrite.getSubjectId().equals(item.getSubjectId())) {
                        // 已存在
                        // 更新
                        paper.remove(paperSubjectReWrite);
                        item.setScore(paperSubjectReWrite.getScore());
                        paperSubjectReWriteService.save(item);
                        break;
                    }
                    // 要删除的数据
                    paperSubjectReWriteService.deleteById(item.getId());
                    //保存数据添加到集合里面
                }
                if (paper.size() > 0) {
                    dataSave(paper1, item.getPaperId(),type);
                }
                return null;
            }).collect(Collectors.toList());
        }else {
            //随机
            List<PaperQuestionReWrite> paper1 = (List<PaperQuestionReWrite>) paper;
            List<PaperQuestionReWrite> base1 = (List<PaperQuestionReWrite>) base;
            base1.stream().map(item -> {
                for (PaperQuestionReWrite paperSubjectReWrite : paper1) {
                    if (paperSubjectReWrite.getQuestionId().equals(item.getQuestionId())) {
                        // 已存在
                        // 更新
                        paper.remove(paperSubjectReWrite);
                        item.setSingleCount(getValue(item.getSingleCount()));
                        item.setMultipleCount(getValue(item.getMultipleCount()));
                        item.setJudgeCount(getValue(item.getJudgeCount()));
                        item.setFillCount(getValue(item.getFillCount()));
                        item.setExplainCount(getValue(item.getExplainCount()));
                        paperQuestionReWriteService.save(item);
                        break;
                    }
                    // 要删除的数据
                    paperQuestionReWriteService.delete(item.getId());
                    //保存数据添加到集合里面
                }
                if (paper.size() > 0) {
                    dataSave(paper1, item.getPaperId(),type);
                }
                return null;
            }).collect(Collectors.toList());
        }
    }
}
